# -*- coding: utf-8 -*-
import pytest
from pytest_jsonreport.plugin import JSONReport
from jenkinsReport.JenkinsCo import JenkinsCo
from jenkinsReport.Robot import Robot

# ------------------------------------企业微信通知--------------------------------
if __name__ == '__main__':
    plugin = JSONReport()
    pytest.main(['-sv', '--alluredir', 'temps', '--clean-alluredir','-W','ignore:Module already imported:pytest.PytestWarning'], plugins=[plugin])

    summary = plugin.report.get("summary")
    # 得到通过，失败，跳过和总执行的用例数
    passed = summary.get("passed", 0)
    failed = summary.get("failed", 0)
    skipped = summary.get("skipped", 0)
    total = summary.get("total", 0)
    # bili = '{:.2f}%'.format(passed / total)
    bili = "%.2f%%" % (passed / total * 100)
    print("共{}条，通过{}条，失败{}条，跳过{}条".format(total, passed, failed, skipped))

    jc = JenkinsCo()
    rb = Robot()
    # 获取测试报告访问地址
    adress = jc.get_allureadress()
    rb.sendMessage(project_name='美导助手', url="测试环境", total=total, passed=passed, failed=failed, skipped=skipped,
                   bili=bili, adress=adress)
